package vashion.azeroth.core.service.tran.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vashion.azeroth.core.manager.personal.tran.PersonalVAccountManager;
import vashion.azeroth.core.personal.tran.pojo.PersonalVAccount;
import vashion.azeroth.core.result.ApiResult;
import vashion.azeroth.core.service.base.BaseService;
import vashion.azeroth.core.service.tran.PersonalVAccountService;
import vashion.azeroth.crm.constant.GenericCrmErrorEnum;

@Service
public class PersonalVAccountServiceImpl extends BaseService implements
		PersonalVAccountService<PersonalVAccount> {

	@Autowired
	private PersonalVAccountManager vaccountManager;

	public ApiResult<PersonalVAccount> queryVAccount(Long memberId) {

		PersonalVAccount vaccount = vaccountManager.getByMemberId(memberId);
		if (null == vaccount) {
			vaccount = new PersonalVAccount();
			vaccount.setMemberId(memberId);
			vaccount.setTotalBalance(0);
			vaccount.setUseableBalance(0);
			vaccount.setFreezeBalance(0);
		}

		return ApiResult.newSuccessResult(vaccount);
	}

	public ApiResult<List<PersonalVAccount>> queryVAccountBy(
			PersonalVAccount personalVAccount) {

		List<PersonalVAccount> vaccountList = null;
		try {
			vaccountList  = vaccountManager.find(personalVAccount);

		} catch (Exception e) {

			return ApiResult.newErrorResult(
					GenericCrmErrorEnum.SYSTEM_ERROR.getErrorCode(),
					GenericCrmErrorEnum.SYSTEM_ERROR.getErrorMessage());

		}
		return ApiResult.newSuccessResult(vaccountList, vaccountList.size());

	}

}
